<?php
/*
	消息通知设置
	参数：$msgtype,$text,$tpldata,$uid,$url,$color
*/
defined('BY_JYA') or exit('error');
list($msgtype,$uid,$store_id,$order_id)=$arguments;
$store=pdo_get('jy_meifa_store',array('id'=>$store_id,'uniacid'=>$_SESSION['uniacid']));
$order=pdo_get('jy_meifa_order',array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
$worker=pdo_get('jy_meifa_worker',array('id'=>$order['wid'],'uniacid'=>$_SESSION['uniacid']));
$order['createtime'] = date('Y/m/d H:i:s',$order['createtime']);
$userinfo=pdo_get('core_members',array('id'=>$uid,'uniacid'=>$_SESSION['uniacid']));
$number=pdo_getcolumn('jy_meifa_num',array('order_id'=>$order_id,'uniacid'=>$_SESSION['uniacid']),'number');
if($number<10){
		$number=$worker['qz'].'000'.$number;
	}		
	elseif($number>9 && $number<100){
		$number=$worker['qz'].'00'.$number;
	}
	else{
		$number=$worker['qz'].'0'.$number;
	}

//过号通知
if($msgtype == 'cancel'){
	$url=custom_url('jy_meifa/order/list/status=3',true);
	$tpldata=array(
		'first'=>array('value'=>'抱歉，由于多次叫号您未及时到店，您的排队'.$number.'已过号','color'=>''),
		'keyword1'=>array('value'=>$number,'color'=>'#ff510'),
		'keyword2'=>array('value'=>$store['title'],'color'=>'#ff510'),
		'keyword3'=>array('value'=>$worker['name'],'color'=>'#ff510'),
		'remark'=>array('value'=>'请安排时间重新取号，谢谢！','color'=>'#ff510'),
	);

	$newsmsg['msgtype']='news';
	$articles[0]['title'] = '过号通知';
	$articles[0]['description'] ='商家名称:'.$store['title']."\n";
	$articles[0]['description'] .='排队号码:'.$number."\n";
	$articles[0]['description'] .='理发师:'.$worker['name']."\n";
	$articles[0]['description'] .='抱歉，由于多次叫号您未及时到店，您的排队'.$number.'已过号，请安排时间重新取号，谢谢！';
	$articles[0]['URL'] =$url;
	$newsmsg['news']['articles'] =$articles;
		
}
//到号通知
elseif($msgtype == 'notice'){
	$url=custom_url('jy_meifa/order/list/status=1',true);
	$tpldata=array(
				'first'=>array('value'=>'到您啦，请前往理发！','color'=>''),
				'keyword1'=>array('value'=>$store['title'],'color'=>'#ff510'),
				'keyword2'=>array('value'=>$number,'color'=>'#ff510'),
				'keyword3'=>array('value'=>$worker['name'],'color'=>'#ff510'),
				'remark'=>array('value'=>'更多消息请查看订单详情','color'=>'#ff510'),
	);	
	$newsmsg['msgtype']='news';
	$articles[0]['title'] = '理发通知'."\n";
	$articles[0]['description'] ='商家名称:'.$store['title']."\n";
	$articles[0]['description'] .='排队号码:'.$number."\n";
	$articles[0]['description'] .='理发师:'.$worker['name']."\n";
	$articles[0]['description'] .='请尽快前往理发，过时可能会被取消哦！';
	$articles[0]['URL'] =$url;
	$newsmsg['news']['articles'] =$articles;
	
}
//取号
elseif($msgtype == 'quhao'){
	$url=custom_url('jy_meifa/order/list/status=0',true);
	$day_start = date('Y-m-d', time());
    $end = date('Y-m-d H:i:s', time());
	$sql = 'SELECT COUNT(1) FROM '. tablename('jy_meifa_order') . ' WHERE uniacid=:uniacid AND wid=:wid AND status=0 AND createtime <:createtime AND createtime >= UNIX_TIMESTAMP( "'.$day_start.'" ) AND createtime <= UNIX_TIMESTAMP( "'.$end.'" )';
	$paidui = pdo_fetch($sql,array(":uniacid" => $_SESSION['uniacid'],":wid" => $worker['id'],":createtime" => $order['createtime']));
	$num=$paidui["COUNT(1)"];
	$tpldata=array(
		'first'=>array('value'=>'排队通知','color'=>''),
		'keyword1'=>array('value'=>$store['title'],'color'=>'#ff510'),
		'keyword2'=>array('value'=>$worker['name'],'color'=>'#ff510'),
		'keyword3'=>array('value'=>$num.'人','color'=>'#ff510'),
		'keyword4'=>array('value'=>date('Y-m-d h:i',$num*$setting['time']*60+time()),'color'=>'#ff510'),
		'remark'=>array('value'=>'请留意实时排队情况，以免过号哦！','color'=>'#ff510'),
	);
	$newsmsg['msgtype']='news';
	$articles[0]['title'] = '取号通知'."\n";
	$articles[0]['description'] ='商家名称:'.$store['title']."\n";
	$articles[0]['description'] .='排队号码:'.$number."\n";
	$articles[0]['description'] .='前面还有:'.$num."\n";
	$articles[0]['description'] .='理发师:'.$worker['name']."\n";
	$articles[0]['description'] .='请留意实时排队情况，以免过号哦！';
	$articles[0]['URL'] =$url;
	$newsmsg['news']['articles'] =$articles;
}
$this->send_message($msgtype,$newsmsg,$tpldata,$uid,$url,$color);